package com.deepclassifieds.daas.api.builder;

import com.deepclassifieds.daas.api.xsd.Shard;
import com.deepclassifieds.daas.api.xsd.Shards;
import com.deepclassifieds.daas.api.xsd.impl.ShardImpl;
import com.deepclassifieds.daas.common.Builder;
import com.deepclassifieds.daas.common.Reject;

public class ShardsBuilder implements Builder<Shards> {
	
	private final Shards shards;
	
	public ShardsBuilder() {
		this.shards = new Shards();
	}
	
	public ShardsBuilder(Shards shards) {
		Reject.ifNull(shards);
		this.shards = new Shards();
		this.shards.getShard().addAll(shards.getShard());
	}

	@Override
	public Shards build() {
		return shards;
	}

	public void addShard(Shard shard) {
		Reject.ifNull(shard);
		shards.getShard().add(shard);
	}
	
	public Shard createAndAddShard(int shardNumber) {
		Shard shard = new ShardImpl();
		shard.setNumber(shardNumber);
		shards.getShard().add(shard);
		return shard;
	}

}
